/*
 * @(#)AttritionRenderer.java 	1.0 2010/07/23
 *
 * Copyright 2010 guyven and David Croft. All rights reserved.
 */
package com.iawg.attrition.engine.renderer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * A template for the Object that will output information to the user.
 * 
 * @author David Croft
 * @author guyven
 * @version 1.0 2010/07/23
 */
public abstract class Renderer<E extends Element> implements Runnable{
	/** The maximum size of the render queue. */
	protected static final int renderCapacity = 40;
	//public static final int ARDOR = 1;
	/** A flag that denotes whether this thread should be running or not and is used to stop the thread. */
	protected boolean isRunning = true;
	/** The queue of elements to be rendered. */
	protected BlockingQueue<E> renderQueue = new ArrayBlockingQueue<E>(renderCapacity);
	
	/** Shuts down the renderer. */
	public void close() {
		this.isRunning = false;
	}
	
	public void run(){
		try {
			while(isRunning)
				render(renderQueue.take());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * Prints a message to the user
	 * 
	 * @param message The message to display.
	 */
	public abstract void print(String message);
	
	/** Display information to the user. */
	public abstract void render(E element);
}